package com.infore.dataReceiving.controller;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.infore.dataReceiving.constant.Constants;
import com.infore.dataReceiving.dto.OverStateDto;
import com.infore.dataReceiving.dto.WaterInstructionsDataDto;
import com.infore.dataReceiving.entity.CheckData;
import com.infore.dataReceiving.entity.HourData;
import com.infore.dataReceiving.entity.RealTimeData;
import com.infore.dataReceiving.entity.RecoveryData;
import com.infore.dataReceiving.entity.SpanCheckData;
import com.infore.dataReceiving.entity.ZeroCheckData;
import com.infore.dataReceiving.enums.ResultStatus;
import com.infore.dataReceiving.enums.WaterQualityTargetLevel;
import com.infore.dataReceiving.externalInterface.siteManage.ISiteManageService;
import com.infore.dataReceiving.outsideInterface.controller.HourDataController;
import com.infore.dataReceiving.select.dto.QueryParamDto;
import com.infore.dataReceiving.select.util.PageObject;
import com.infore.dataReceiving.select.util.QueryCondition;
import com.infore.dataReceiving.service.IInstructionsService;
import com.infore.dataReceiving.util.Water2018InstructionsHandleUtil;
import com.infore.dataReceiving.util.JsonUtils;
import com.infore.dataReceiving.util.Page;
import com.infore.dataReceiving.util.ResultEntity;
import com.infore.dataReceiving.util.WaterQualityUtil;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Controller
public class Water2018InstructionsController {
	
	@Autowired
	private IInstructionsService iInstructionsService;
	
	@Autowired
	private ISiteManageService iSiteManageService;
	@Autowired
	private HourDataController hourDataController;
	
//	@Autowired
//	private ISiteManageService ISiteManageService;
	
	@ApiOperation(value = "获取实时数据", notes = "获取选定时间范围的实时数据")
    @ApiImplicitParams({@ApiImplicitParam(name = "beginTime", value = "开始时间", paramType = "query", required = true, dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", required = true, dataType = "String")})
	@RequestMapping(value = "/queryRealTimeData", method = RequestMethod.GET)
	@ResponseBody
	public ResultEntity queryRealTimeData(String beginTime,String endTime) throws Exception {
		Timestamp t1 = Water2018InstructionsHandleUtil.getTimestamp(beginTime);
		Timestamp t2 = Water2018InstructionsHandleUtil.getTimestamp(endTime);
		List<RealTimeData> list = iInstructionsService.queryRealTimeData(t1,t2);
		return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setDataList(list);
	}
	
	@ApiOperation(value = "获取小时数据", notes = "获取选定时间范围的小时数据")
    @ApiImplicitParams({@ApiImplicitParam(name = "beginTime", value = "开始时间", paramType = "query", required = true, dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", required = true, dataType = "String")})
	@RequestMapping(value = "/queryHourData", method = RequestMethod.GET)
	@ResponseBody
	public ResultEntity queryHourData(String beginTime,String endTime) throws Exception {
		Timestamp t1 = Water2018InstructionsHandleUtil.getTimestamp(beginTime);
		Timestamp t2 = Water2018InstructionsHandleUtil.getTimestamp(endTime);
		List<HourData> list = iInstructionsService.queryHourData(t1,t2);
		return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setDataList(list);
	}
	
	@ApiOperation(value = "获取核查数据", notes = "获取选定时间范围的核查数据")
//    @ApiImplicitParams({@ApiImplicitParam(name = "beginTime", value = "开始时间", paramType = "query", required = true, dataType = "String"),
//            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", required = true, dataType = "String")})
	@RequestMapping(value = "/queryCheckData", method = RequestMethod.GET)
	@ResponseBody
	public ResultEntity queryCheckData() throws Exception {
//		Timestamp t1 = InstructionsHandleUtil.getTimestamp(beginTime);
//		Timestamp t2 = InstructionsHandleUtil.getTimestamp(endTime);
		List<CheckData> list = iInstructionsService.queryCheckData();
		return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setDataList(list);
	}
	
	@ApiOperation(value = "获取未标识的实时数据", notes = "获取未标识的实时数据")
//  @ApiImplicitParams({@ApiImplicitParam(name = "beginTime", value = "开始时间", paramType = "query", required = true, dataType = "String"),
//          @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", required = true, dataType = "String")})
	@RequestMapping(value = "/queryNoFlagRealData", method = RequestMethod.GET)
	@ResponseBody
	public ResultEntity queryNoFlagRealData() throws Exception {
//		Timestamp t1 = InstructionsHandleUtil.getTimestamp(beginTime);
//		Timestamp t2 = InstructionsHandleUtil.getTimestamp(endTime);
		List<RealTimeData> list = iInstructionsService.queryNoFlagRealData();
		return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setDataList(list);
	}
	
	@ApiOperation(value = "获取加标回收率数据", notes = "获取选定时间范围的加标回收率数据")
//    @ApiImplicitParams({@ApiImplicitParam(name = "beginTime", value = "开始时间", paramType = "query", required = true, dataType = "String"),
//            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", required = true, dataType = "String")})
	@RequestMapping(value = "/queryRecoveryData", method = RequestMethod.GET)
	@ResponseBody
	public ResultEntity queryRecoveryData() throws Exception {
//		Timestamp t1 = InstructionsHandleUtil.getTimestamp(beginTime);
//		Timestamp t2 = InstructionsHandleUtil.getTimestamp(endTime);
		List<RecoveryData> list = iInstructionsService.queryRecoveryData();
		return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setDataList(list);
	}
	
	@ApiOperation(value = "获取零点核查数据", notes = "获取选定时间范围的零点核查数据")
    @ApiImplicitParams({
//    	@ApiImplicitParam(name = "beginTime", value = "开始时间", paramType = "query", required = true, dataType = "String"),
//            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", required = true, dataType = "String"),
            @ApiImplicitParam(name = "factorCode", value = "监测项编码", paramType = "query", required = true, dataType = "String")})
	@RequestMapping(value = "/queryZeroCheckData", method = RequestMethod.GET)
	@ResponseBody
	public ResultEntity queryZeroCheckData(String factorCode) throws Exception {
//		Timestamp t1 = InstructionsHandleUtil.getTimestamp(beginTime);
//		Timestamp t2 = InstructionsHandleUtil.getTimestamp(endTime);
		List<ZeroCheckData> list = iInstructionsService.queryZeroCheckData(factorCode);
		return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setDataList(list);
	}
	
	@ApiOperation(value = "获取跨度核查数据", notes = "获取选定时间范围的跨度核查数据")
    @ApiImplicitParams({
//    	@ApiImplicitParam(name = "beginTime", value = "开始时间", paramType = "query", required = true, dataType = "String"),
//            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", required = true, dataType = "String"),
            @ApiImplicitParam(name = "factorCode", value = "监测项编码", paramType = "query", required = true, dataType = "String")})
	@RequestMapping(value = "/querySpanCheckData", method = RequestMethod.GET)
	@ResponseBody
	public ResultEntity querySpanCheckData(String factorCode) throws Exception {
//		Timestamp t1 = InstructionsHandleUtil.getTimestamp(beginTime);
//		Timestamp t2 = InstructionsHandleUtil.getTimestamp(endTime);
		List<SpanCheckData> list = iInstructionsService.querySpanCheckData(factorCode);
		return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setDataList(list);
	}
	
	
	
	
	@ApiOperation(value = "获取实时数据", notes = "获取实时数据")
    @ApiImplicitParams({@ApiImplicitParam(name = "mn", value = "站点mn号", paramType = "query", required = true, dataType = "String"),
    	 @ApiImplicitParam(name = "isNnusual", value = "是否查看异常数据all全部数据，unusual异常数据，normal正常数据", paramType = "query", required = true, dataType = "String"),
    	@ApiImplicitParam(name = "pageNum", value = "第几页", paramType = "query", required = true, dataType = "String"),
    	@ApiImplicitParam(name = "pageSize", value = "每页多少条记录", paramType = "query", required = true, dataType = "String")
    })
	@RequestMapping(value = "/queryRowToColRealTimeData", method = RequestMethod.GET)
	@ResponseBody
	public ResultEntity queryRealTimeData(String mn,String pageNum,String pageSize,String isNnusual) throws Exception {
		List<Map<String, Object>> list = iInstructionsService.queryRowToColRealTimeData(mn,pageNum,pageSize);
		
		QueryParamDto queryParamDto = JsonUtils.readJsonFromClassPath("/queryParam/siteQuery.json", QueryParamDto.class);
		ResultEntity resultEntity = iSiteManageService.queryStation(queryParamDto);
		Map<String, Object> dataMap = (Map<String, Object>)resultEntity.getContent();
		List<Map<String, Object>> siteList = (List<Map<String, Object>>)dataMap.get("dataList");
		Map<String, Map<String, Object>> siteMap = new HashMap<>();
		for(Map<String, Object> map:siteList) {
			siteMap.put(map.get("stationMn").toString(), map);
		}
		List<WaterInstructionsDataDto> unualList = new ArrayList<>();
		List<WaterInstructionsDataDto> normalList = new ArrayList<>();
		List<WaterInstructionsDataDto> finalList = new ArrayList<>();
		SimpleDateFormat sdfDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//		for(Map<String, Object> map:list) {
//			WaterInstructionsDataDto waterInstructionsDataDto = new WaterInstructionsDataDto();
//			waterInstructionsDataDto.setProvince("重庆市");
//			String mns = map.get("mn").toString();
//			waterInstructionsDataDto.setBasin(siteMap.get(mns).get("basinn_basinnName").toString());
//			waterInstructionsDataDto.setStationName(siteMap.get(mns).get("stationName").toString());
//			waterInstructionsDataDto.setStationType(siteMap.get(mns).get("stationType1").toString());
//			waterInstructionsDataDto.setTargerWaterQuality(siteMap.get(mns).get("targerWaterQuality")==null?null:siteMap.get(mns).get("targerWaterQuality").toString());
//			waterInstructionsDataDto.setCityName(siteMap.get(mns).get("cityName")==null?null:siteMap.get(mns).get("cityName").toString());
//			waterInstructionsDataDto.setAreaName(siteMap.get(mns).get("areaName")==null?null:siteMap.get(mns).get("areaName").toString());
////			if("40000000000001".equals(mns)) {
////				waterInstructionsDataDto.setStationName("水站1");
////			}else if("40000000000002".equals(mns)) {
////				waterInstructionsDataDto.setStationName("水站2");
////			}else if("40000000000003".equals(mns)) {
////				waterInstructionsDataDto.setStationName("污染源站点1");
////			}else {
////				waterInstructionsDataDto.setStationName("测试站");
////			}
//			waterInstructionsDataDto.setMn(map.get("mn")==null?null:map.get("mn").toString());
//			waterInstructionsDataDto.setDataTime(sdfDateFormat.format((Date)map.get("dataTime")));
//			waterInstructionsDataDto.setStationState("0");
//			waterInstructionsDataDto.setWaterQuality("1");
//			waterInstructionsDataDto.setW01010(map.get("w01010")==null?null:map.get("w01010").toString());
//			waterInstructionsDataDto.setW01001(map.get("w01001")==null?null:map.get("w01001").toString());
//			waterInstructionsDataDto.setW01009(map.get("w01009")==null?null:map.get("w01009").toString());
//			waterInstructionsDataDto.setW01003(map.get("w01003")==null?null:map.get("w01003").toString());
//			waterInstructionsDataDto.setW01014(map.get("w01014")==null?null:map.get("w01014").toString());
//			waterInstructionsDataDto.setW01019(map.get("w01019")==null?null:map.get("w01019").toString());
//			waterInstructionsDataDto.setW21003(map.get("w21003")==null?null:map.get("w21003").toString());
//			waterInstructionsDataDto.setW21011(map.get("w21011")==null?null:map.get("w21011").toString());
//			waterInstructionsDataDto.setW21001(map.get("w21001")==null?null:map.get("w21001").toString());
//			waterInstructionsDataDto.setW01018(map.get("w01018")==null?null:map.get("w01018").toString());
//			waterInstructionsDataDto.setW01016(map.get("w01016")==null?null:map.get("w01016").toString());
//			finalList.add(waterInstructionsDataDto);
//		}
//		WaterQualityUtil.setWaterQuality(finalList);
		for(Map<String, Object> map:list) {
			String mns = map.get("mn").toString();
			List<WaterInstructionsDataDto> dtoList = new ArrayList<WaterInstructionsDataDto>();
			WaterInstructionsDataDto waterInstructionsDataDto = new WaterInstructionsDataDto();
			String provinceName = siteMap.get(mns).get("provinceId_areaName") == null ? "" : siteMap.get(mns).get("provinceId_areaName").toString();
			waterInstructionsDataDto.setProvince(provinceName);
			waterInstructionsDataDto.setBasin(siteMap.get(mns).get("basinn_basinnName").toString());
			waterInstructionsDataDto.setStationName(siteMap.get(mns).get("stationName").toString());
			waterInstructionsDataDto.setCityName(siteMap.get(mns).get("cityName")==null?null:siteMap.get(mns).get("cityName").toString());
			waterInstructionsDataDto.setAreaName(siteMap.get(mns).get("areaName")==null?null:siteMap.get(mns).get("areaName").toString());
			String targerWaterQuality = siteMap.get(mns).get("targerWaterQuality") == null ? "-" : siteMap.get(mns).get("targerWaterQuality").toString();
			//			if("40000000000001".equals(mns)) {
//				waterInstructionsDataDto.setStationName("水站1");
//			}else if("40000000000002".equals(mns)) {
//				waterInstructionsDataDto.setStationName("水站2");
//			}else if("40000000000003".equals(mns)) {
//				waterInstructionsDataDto.setStationName("污染源站点1");
//			}else {
//				waterInstructionsDataDto.setStationName("测试站");
//			}
			waterInstructionsDataDto.setTargerWaterQuality(targerWaterQuality);
			waterInstructionsDataDto.setMn(map.get("mn")==null?null:map.get("mn").toString());
			waterInstructionsDataDto.setDataTime(sdfDateFormat.format((Date)map.get("dataTime")));
			waterInstructionsDataDto.setStationState("0");
			String w01010 = map.get("w01010")==null?null:map.get("w01010").toString();  //水温
			String w01001 = map.get("w01001")==null?null:map.get("w01001").toString(); //pH值"
			String w01009 = map.get("w01009")==null?null:map.get("w01009").toString();;  //溶解氧"
			String w01003 = map.get("w01003")==null?null:map.get("w01003").toString();;  //浑浊度"
			String w01014 = map.get("w01014")==null?null:map.get("w01014").toString();;  //电导率"
			String w01019 = map.get("w01019")==null?null:map.get("w01019").toString();;  //高锰酸盐指数
			String w21003 = map.get("w21003")==null?null:map.get("w21003").toString();;  //氨氮
			String w21011 = map.get("w21011")==null?null:map.get("w21011").toString();;  //总磷
			String w21001 = map.get("w21001")==null?null:map.get("w21001").toString();;  //总氮
			String w01018 = map.get("w01018")==null?null:map.get("w01018").toString();;  //CODcr
			String w01016 = map.get("w01016")==null?null:map.get("w01016").toString();;  //叶绿素
			//waterInstructionsDataDto.setWaterQuality("1");
			waterInstructionsDataDto.setW01010(w01010);
			waterInstructionsDataDto.setW01001(w01001);
			waterInstructionsDataDto.setW01009(w01009);
			waterInstructionsDataDto.setW01003(w01003);
			waterInstructionsDataDto.setW01014(w01014);
			waterInstructionsDataDto.setW01019(w01019);
			waterInstructionsDataDto.setW21003(w21003);
			waterInstructionsDataDto.setW21011(w21011);
			waterInstructionsDataDto.setW21001(w21001);
			waterInstructionsDataDto.setW01018(w01018);
			waterInstructionsDataDto.setW01016(w01016);
			dtoList.add(waterInstructionsDataDto);
			//判断单个因子是不是超标
			//暂时单个因子的超标等级限制为三级
			int singlLevel = 3;
			String w01010State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w01010", w01010), singlLevel);
			String w01001State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w01001", w01001), singlLevel);
			String w01009State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w01009", w01009), singlLevel);
			String w01003State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w01003", w01003), singlLevel);
			String w01014State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w01014", w01014), singlLevel);
			String w01019State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w01019", w01019), singlLevel);
			String w21003State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w21003", w21003), singlLevel);
			String w21011State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w21011", w21011), singlLevel);
			String w21001State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w21001", w21001), singlLevel);
			String w01018State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w01018", w01018), singlLevel);
			String w01016State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w01016", w01016), singlLevel);
			waterInstructionsDataDto.setW01001State(w01001State);
			waterInstructionsDataDto.setW01003State(w01003State);
			waterInstructionsDataDto.setW01009State(w01009State);
			waterInstructionsDataDto.setW01010State(w01010State);
			waterInstructionsDataDto.setW01014State(w01014State);
			waterInstructionsDataDto.setW01016State(w01016State);
			waterInstructionsDataDto.setW01018State(w01018State);
			waterInstructionsDataDto.setW01019State(w01019State);
			waterInstructionsDataDto.setW21001State(w21001State);
			waterInstructionsDataDto.setW21003State(w21003State);
			waterInstructionsDataDto.setW21011State(w21011State);
			//计算综合水质等级
			WaterQualityUtil.setWaterQuality(dtoList);
			String level = waterInstructionsDataDto.getWaterQuality();
			String flag = "normal";
			//判断整条记录是不是超标数据
			if(NumberUtils.isNumber(level)) {
				String arm = WaterQualityTargetLevel.getDesc(targerWaterQuality).getStatusCode();//目标水质等级
				int armLevel = NumberUtils.createInteger(arm);
				int levelInt = NumberUtils.createInteger(level);//实际等级
				flag = levelInt > armLevel ? "unusual":"normal";
				waterInstructionsDataDto.setIsNnusual(flag);
			}
			if ("unusual".equals(flag)) {
				unualList.add(waterInstructionsDataDto);
			} else if("normal".equals(flag)){
				normalList.add(waterInstructionsDataDto);
			}
			finalList.add(waterInstructionsDataDto);
		}
		if ("unusual".equals(isNnusual)) {
			finalList = unualList;
		} else if("normal".equals(isNnusual)){
			finalList = normalList;
		}
		int count = iInstructionsService.queryRowToColRealTimeDataCount(mn);
		int yu = count/Integer.valueOf(pageSize);
		int mo = count%Integer.valueOf(pageSize);
		if(mo>0) {
			yu+=1;
		}
		
		Page<WaterInstructionsDataDto> page = new Page<WaterInstructionsDataDto>();
		page.setList(finalList);
		page.setPageNo(Integer.valueOf(pageNum));
		page.setPageSize(Integer.valueOf(pageSize));
		page.setTotalPages(yu);
		page.setTotalRecords(count);
		
		return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setPage(page);
	}
	@ApiOperation(value = "获取监测站实时监控", notes = "获取监测站实时监控")
    @ApiImplicitParams({@ApiImplicitParam(name = "mn", value = "站点mn号", paramType = "query", required = true, dataType = "String")})
    @RequestMapping(value = "/realDataState", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity realDataState(String mn) throws Exception {
	    ResultEntity re = this.queryRealTimeData(mn, "1", "10000","all");
        HashMap<String, Object> content = (HashMap<String, Object>) re.getContent();
        List<WaterInstructionsDataDto> finalList = (List<WaterInstructionsDataDto>) content.get("dataList");
        SimpleDateFormat sdfDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long now = new Date().getTime();
        int zcNum = 0, cbNum = 0, ycNum = 0, liNum = 0;
        
        for (WaterInstructionsDataDto data : finalList) {
            String time = data.getDataTime();
            Date date = sdfDateFormat.parse(time);
            long cnum = now - date.getTime();
            int level = Integer.valueOf(data.getWaterQuality());
            if(cnum <= 5*60*60*1000) {
                if(level > 3) {
                    cbNum ++;
                }else {
                    zcNum ++; 
                }
            }else {
                liNum ++;
            }
        }
        List<Map<String, Object>> result = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        map.put("name", "正常");
        map.put("value", zcNum);
        result.add(map);
        map = new HashMap<>();
        map.put("name", "超标");
        map.put("value", cbNum);
        result.add(map);
        map = new HashMap<>();
        map.put("name", "异常");
        map.put("value", ycNum);
        result.add(map);
        map = new HashMap<>();
        map.put("name", "离线");
        map.put("value", liNum);
        result.add(map);
        return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setDataList(result);
	}
	
	@ApiOperation(value = "获取多监测站实时在线联网率统计", notes = "获取多监测站实时在线联网率统计")
    @ApiImplicitParams({@ApiImplicitParam(name = "mn", value = "站点mn号", paramType = "query", required = true, dataType = "String")})
    @RequestMapping(value = "/realDataNetStateLv", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity realDataNetStateLv(String mn) throws Exception {
        ResultEntity re = hourDataController.queryRealTimeData(mn, "1", "10000","all");
        HashMap<String, Object> content = (HashMap<String, Object>) re.getContent();
        List<WaterInstructionsDataDto> finalList = (List<WaterInstructionsDataDto>) content.get("dataList");
        int zxNum = 0, tyNum = 0,  liNum = 0;
        int total = mn.split(",").length;
        if(total == 0) {
            return new ResultEntity(ResultStatus.ERROR, "监测站mn未传入");
        }
        for (WaterInstructionsDataDto data : finalList) {
            String state = data.getStationState();
            if(StringUtils.isBlank(state) || state.equals("0")) {
                liNum ++;
            }else {
                zxNum ++;
            }
        }
        tyNum = total - (zxNum + liNum);
        int lv = zxNum * 100 / total;
        Map<String, Object> map = new HashMap<>();
        map.put("lv", lv);
        map.put("zxNum", zxNum);
        map.put("liNum", liNum);
        map.put("total", total);
        map.put("tyNum", tyNum);
        return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setInfo(map);
    }
	
	@ApiOperation(value = "获取实时数据水质等级排名", notes = "获取实时数据水质等级")
    @ApiImplicitParams({@ApiImplicitParam(name = "mn", value = "站点mn号", paramType = "query", required = true, dataType = "String")})
    @RequestMapping(value = "/queryRealTimeWaterQualitySort", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity queryRealTimeWaterQualitySort(String mn) {
	    ResultEntity re = null;
        try {
            re = hourDataController.queryRealTimeData(mn, "1", "10000","all");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
	    HashMap<String, Object> content = (HashMap<String, Object>) re.getContent();
	    List<WaterInstructionsDataDto> finalList = (List<WaterInstructionsDataDto>) content.get("dataList");
	  //  WaterQualityUtil.setWaterQuality(finalList);
	    
	    //排序
	    Collections.sort(finalList, Comparator.comparing(WaterInstructionsDataDto::getWaterQuality));
	    for (int i = 0; i < finalList.size(); i++) {
	        finalList.get(i).setRanking(i+1);
        }
	    return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setDataList(finalList);
	}
	
	@ApiOperation(value = "获取实时监测站点超标情况", notes = "获取实时监测站点超标情况")
    @ApiImplicitParams({@ApiImplicitParam(name = "mn", value = "站点mn号", paramType = "query", required = true, dataType = "String")})
    @RequestMapping(value = "/queryRealTimeOverDate", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity queryRealTimeOverDate(String mn) {
        ResultEntity re = null;
        try {
            re = hourDataController.queryRealTimeData(mn, "1", "10000","all");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        HashMap<String, Object> content = (HashMap<String, Object>) re.getContent();
        List<WaterInstructionsDataDto> finalList = (List<WaterInstructionsDataDto>) content.get("dataList");
        WaterQualityUtil.setWaterQuality(finalList);
        List<OverStateDto> list = WaterQualityUtil.wrapOverStateDtoList(finalList);
        return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setDataList(list);
    }
	
	@ApiOperation(value = "获取监测站联网率排名", notes = "获取监测站联网率排名")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "mn", value = "站点mn号", paramType = "query", required = true, dataType = "String"),
        @ApiImplicitParam(name = "type", value = "时间类型", paramType = "query", required = true, dataType = "int")
    })
    @RequestMapping(value = "/queryStationsNetworkSort", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity queryStationsNetworkSort(String mn, int type) throws IOException {
        ResultEntity re = null;
        try {
            re = hourDataController.queryRealTimeData(mn, "1", "10000","all");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        HashMap<String, Object> content = (HashMap<String, Object>) re.getContent();
        List<WaterInstructionsDataDto> finalList = (List<WaterInstructionsDataDto>) content.get("dataList");
        Map<String, WaterInstructionsDataDto> dataMap2 = new HashMap<>();
        for (WaterInstructionsDataDto dto : finalList) {
            dataMap2.put(dto.getMn(), dto);
        }
      //  WaterQualityUtil.setWaterQuality(finalList);
        QueryParamDto queryParamDto = JsonUtils.readJsonFromClassPath("/queryParam/siteQueryBasic.json", QueryParamDto.class);
        QueryCondition q = new QueryCondition();
        String mnList = "stationMn", oper ="in";
        q.setOperator(Arrays.asList(oper));
        q.setProperty(Arrays.asList(mnList));
        q.setContent(Arrays.asList(mn));
        queryParamDto.setQueryCondition(q);
        ResultEntity resultEntity = iSiteManageService.queryStation(queryParamDto);
        Map<String, Object> dataMap = (Map<String, Object>)resultEntity.getContent();
        List<Map<String, Object>> siteList = (List<Map<String, Object>>)dataMap.get("dataList");
        Map<String, Map<String, Object>> siteMap = new HashMap<>();
        int zc = 97, lx = 56;
        double random = 6*type;
        double randomLX = 2*type;
        List<Map<String, Object>> stationNetList = new ArrayList<>();
        Map<String, Object> netMap = null;
        WaterInstructionsDataDto dto = null;
        for(Map<String, Object> map:siteList) {
            siteMap.put(map.get("stationMn").toString(), map);
            String stationMn = map.get("stationMn").toString();
            dto = dataMap2.get(stationMn);
            netMap = new HashMap<>();
            stationNetList.add(netMap);
            netMap.put("name", map.get("stationName").toString());
            netMap.put("value", 0);
            if(dto != null) {
               String state =  dto.getStationState();
               if(state.equals("0")) {
                   netMap.put("value", 56 - randomLX); 
               }else {
                   netMap.put("value", 96 - random); 
               }
            }
        }  
        //排序
        Collections.sort(stationNetList, new Comparator<Map<String, Object>>() {
            @Override
            public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                return Double.valueOf(o2.get("value").toString()).compareTo(Double.valueOf(o1.get("value").toString()));
            }
        });
        Map<String, Object> resultMap = new HashMap<>();
        List<String> names = new ArrayList<>();
        List<Double> values = new ArrayList<>();
        resultMap.put("names", names);
        resultMap.put("values", values);
        for (Map<String,Object> map : stationNetList) {
            names.add(map.get("name").toString());
            values.add(Double.valueOf(map.get("value").toString()));
        }
        
        return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setInfo(resultMap);
    }
	
	
	@ApiOperation(value = "获取行转列实时数据", notes = "获取选定时间范围的行转列实时数据")
    @ApiImplicitParams({@ApiImplicitParam(name = "mn", value = "站点mn号", paramType = "query", required = true, dataType = "String"),
    		@ApiImplicitParam(name = "beginTime", value = "开始时间", paramType = "query", required = true, dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", required = true, dataType = "String"),
            @ApiImplicitParam(name = "pageNum", value = "第几页", paramType = "query", required = true, dataType = "String"),
        	@ApiImplicitParam(name = "pageSize", value = "每页多少条记录", paramType = "query", required = true, dataType = "String")
    })
	@RequestMapping(value = "/queryRowToColRealTimeData1", method = RequestMethod.GET)
	@ResponseBody
	public ResultEntity queryRowToColRealTimeData1(String mn,String beginTime,String endTime,String pageNum,String pageSize) throws Exception {
		List<Map<String, Object>> list = iInstructionsService.queryRowToColRealTimeData1(mn,beginTime,endTime,pageNum,pageSize);
		QueryParamDto queryParamDto = JsonUtils.readJsonFromClassPath("/queryParam/siteQuery.json", QueryParamDto.class);
		ResultEntity resultEntity = iSiteManageService.queryStation(queryParamDto);
		Map<String, Object> dataMap = (Map<String, Object>)resultEntity.getContent();
		List<Map<String, Object>> siteList = (List<Map<String, Object>>)dataMap.get("dataList");
		Map<String, Map<String, Object>> siteMap = new HashMap<>();
		for(Map<String, Object> map:siteList) {
			siteMap.put(map.get("stationMn").toString(), map);
		}
		
		List<WaterInstructionsDataDto> finalList = new ArrayList<>();
		SimpleDateFormat sdfDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		for(Map<String, Object> map:list) {
			WaterInstructionsDataDto waterInstructionsDataDto = new WaterInstructionsDataDto();
			waterInstructionsDataDto.setProvince("重庆市");
			String mns = map.get("mn").toString();
			waterInstructionsDataDto.setBasin(siteMap.get(mns).get("basinn_basinnName").toString());
			waterInstructionsDataDto.setStationName(siteMap.get(mns).get("stationName").toString());
			waterInstructionsDataDto.setCityName(siteMap.get(mns).get("cityName")==null?null:siteMap.get(mns).get("cityName").toString());
			waterInstructionsDataDto.setAreaName(siteMap.get(mns).get("areaName")==null?null:siteMap.get(mns).get("areaName").toString());
//			if("40000000000001".equals(mns)) {
//				waterInstructionsDataDto.setStationName("水站1");
//			}else if("40000000000002".equals(mns)) {
//				waterInstructionsDataDto.setStationName("水站2");
//			}else if("40000000000003".equals(mns)) {
//				waterInstructionsDataDto.setStationName("污染源站点1");
//			}else {
//				waterInstructionsDataDto.setStationName("测试站");
//			}
			waterInstructionsDataDto.setMn(map.get("mn")==null?null:map.get("mn").toString());
			waterInstructionsDataDto.setDataTime(sdfDateFormat.format((Date)map.get("dataTime")));
			waterInstructionsDataDto.setStationState("0");
			waterInstructionsDataDto.setWaterQuality("1");
			waterInstructionsDataDto.setW01010(map.get("w01010")==null?null:map.get("w01010").toString());
			waterInstructionsDataDto.setW01001(map.get("w01001")==null?null:map.get("w01001").toString());
			waterInstructionsDataDto.setW01009(map.get("w01009")==null?null:map.get("w01009").toString());
			waterInstructionsDataDto.setW01003(map.get("w01003")==null?null:map.get("w01003").toString());
			waterInstructionsDataDto.setW01014(map.get("w01014")==null?null:map.get("w01014").toString());
			waterInstructionsDataDto.setW01019(map.get("w01019")==null?null:map.get("w01019").toString());
			waterInstructionsDataDto.setW21003(map.get("w21003")==null?null:map.get("w21003").toString());
			waterInstructionsDataDto.setW21011(map.get("w21011")==null?null:map.get("w21011").toString());
			waterInstructionsDataDto.setW21001(map.get("w21001")==null?null:map.get("w21001").toString());
			waterInstructionsDataDto.setW01018(map.get("w01018")==null?null:map.get("w01018").toString());
			waterInstructionsDataDto.setW01016(map.get("w01016")==null?null:map.get("w01016").toString());
			finalList.add(waterInstructionsDataDto);
		}
		
		int count = iInstructionsService.queryRowToColRealTimeDataCount1(mn,beginTime,endTime);
		int yu = count/Integer.valueOf(pageSize);
		int mo = count%Integer.valueOf(pageSize);
		if(mo>0) {
			yu+=1;
		}
		
		Page<WaterInstructionsDataDto> page = new Page<WaterInstructionsDataDto>();
		page.setList(finalList);
		page.setPageNo(Integer.valueOf(pageNum));
		page.setPageSize(Integer.valueOf(pageSize));
		page.setTotalPages(yu);
		page.setTotalRecords(count);
		
		return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setPage(page);
	}
	
	@ApiOperation(value = "获取行转列小时数据", notes = "获取选定时间范围的行转列小时数据")
    @ApiImplicitParams({@ApiImplicitParam(name = "mn", value = "站点mn号", paramType = "query", required = true, dataType = "String"),
    		@ApiImplicitParam(name = "beginTime", value = "开始时间", paramType = "query", required = true, dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", required = true, dataType = "String"),
            @ApiImplicitParam(name = "isNnusual", value = "是否查看异常数据all全部数据，unusual异常数据，normal正常数据", paramType = "query", required = true, dataType = "String"),
            @ApiImplicitParam(name = "pageNum", value = "第几页", paramType = "query", required = true, dataType = "String"),
        	@ApiImplicitParam(name = "pageSize", value = "每页多少条记录", paramType = "query", required = true, dataType = "String")
    })
	@RequestMapping(value = "/queryRowToColHourData", method = RequestMethod.GET)
	@ResponseBody
	public ResultEntity queryRowToColHourData(String mn,String beginTime,String endTime,String pageNum,String pageSize,String isNnusual) throws Exception {
		List<Map<String, Object>> list = iInstructionsService.queryRowToColHourData(mn,beginTime,endTime,pageNum,pageSize);
		QueryParamDto queryParamDto = JsonUtils.readJsonFromClassPath("/queryParam/siteQuery.json", QueryParamDto.class);
		ResultEntity resultEntity = iSiteManageService.queryStation(queryParamDto);
		Map<String, Object> dataMap = (Map<String, Object>)resultEntity.getContent();
		List<Map<String, Object>> siteList = (List<Map<String, Object>>)dataMap.get("dataList");
		Map<String, Map<String, Object>> siteMap = new HashMap<>();
		for(Map<String, Object> map:siteList) {
			siteMap.put(map.get("stationMn").toString(), map);
		}
		List<WaterInstructionsDataDto> unualList = new ArrayList<>();
		List<WaterInstructionsDataDto> normalList = new ArrayList<>();
		List<WaterInstructionsDataDto> finalList = new ArrayList<>();
		SimpleDateFormat sdfDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		for(Map<String, Object> map:list) {
			String mns = map.get("mn").toString();
			List<WaterInstructionsDataDto> dtoList = new ArrayList<WaterInstructionsDataDto>();
			WaterInstructionsDataDto waterInstructionsDataDto = new WaterInstructionsDataDto();
			String provinceName = siteMap.get(mns).get("provinceId_areaName") == null ? "" : siteMap.get(mns).get("provinceId_areaName").toString();
			waterInstructionsDataDto.setProvince(provinceName);
			waterInstructionsDataDto.setBasin(siteMap.get(mns).get("basinn_basinnName").toString());
			waterInstructionsDataDto.setStationName(siteMap.get(mns).get("stationName").toString());
			waterInstructionsDataDto.setCityName(siteMap.get(mns).get("cityName")==null?null:siteMap.get(mns).get("cityName").toString());
			waterInstructionsDataDto.setAreaName(siteMap.get(mns).get("areaName")==null?null:siteMap.get(mns).get("areaName").toString());
			String targerWaterQuality = siteMap.get(mns).get("targerWaterQuality") == null ? "-" : siteMap.get(mns).get("targerWaterQuality").toString();
			//			if("40000000000001".equals(mns)) {
//				waterInstructionsDataDto.setStationName("水站1");
//			}else if("40000000000002".equals(mns)) {
//				waterInstructionsDataDto.setStationName("水站2");
//			}else if("40000000000003".equals(mns)) {
//				waterInstructionsDataDto.setStationName("污染源站点1");
//			}else {
//				waterInstructionsDataDto.setStationName("测试站");
//			}
			waterInstructionsDataDto.setTargerWaterQuality(targerWaterQuality);
			waterInstructionsDataDto.setMn(map.get("mn")==null?null:map.get("mn").toString());
			waterInstructionsDataDto.setDataTime(sdfDateFormat.format((Date)map.get("dataTime")));
			waterInstructionsDataDto.setStationState("0");
			String w01010 = map.get("w01010")==null?null:map.get("w01010").toString();  //水温
			String w01001 = map.get("w01001")==null?null:map.get("w01001").toString(); //pH值"
			String w01009 = map.get("w01009")==null?null:map.get("w01009").toString();;  //溶解氧"
			String w01003 = map.get("w01003")==null?null:map.get("w01003").toString();;  //浑浊度"
			String w01014 = map.get("w01014")==null?null:map.get("w01014").toString();;  //电导率"
			String w01019 = map.get("w01019")==null?null:map.get("w01019").toString();;  //高锰酸盐指数
			String w21003 = map.get("w21003")==null?null:map.get("w21003").toString();;  //氨氮
			String w21011 = map.get("w21011")==null?null:map.get("w21011").toString();;  //总磷
			String w21001 = map.get("w21001")==null?null:map.get("w21001").toString();;  //总氮
			String w01018 = map.get("w01018")==null?null:map.get("w01018").toString();;  //CODcr
			String w01016 = map.get("w01016")==null?null:map.get("w01016").toString();;  //叶绿素
			//waterInstructionsDataDto.setWaterQuality("1");
			waterInstructionsDataDto.setW01010(w01010);
			waterInstructionsDataDto.setW01001(w01001);
			waterInstructionsDataDto.setW01009(w01009);
			waterInstructionsDataDto.setW01003(w01003);
			waterInstructionsDataDto.setW01014(w01014);
			waterInstructionsDataDto.setW01019(w01019);
			waterInstructionsDataDto.setW21003(w21003);
			waterInstructionsDataDto.setW21011(w21011);
			waterInstructionsDataDto.setW21001(w21001);
			waterInstructionsDataDto.setW01018(w01018);
			waterInstructionsDataDto.setW01016(w01016);
			dtoList.add(waterInstructionsDataDto);
			//判断单个因子是不是超标
			//暂时单个因子的超标等级限制为三级
			int singlLevel = 3;
			String w01010State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w01010", w01010), singlLevel);
			String w01001State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w01001", w01001), singlLevel);
			String w01009State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w01009", w01009), singlLevel);
			String w01003State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w01003", w01003), singlLevel);
			String w01014State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w01014", w01014), singlLevel);
			String w01019State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w01019", w01019), singlLevel);
			String w21003State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w21003", w21003), singlLevel);
			String w21011State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w21011", w21011), singlLevel);
			String w21001State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w21001", w21001), singlLevel);
			String w01018State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w01018", w01018), singlLevel);
			String w01016State = WaterQualityUtil.OverData(WaterQualityUtil.getWaterLevel("w01016", w01016), singlLevel);
			waterInstructionsDataDto.setW01001State(w01001State);
			waterInstructionsDataDto.setW01003State(w01003State);
			waterInstructionsDataDto.setW01009State(w01009State);
			waterInstructionsDataDto.setW01010State(w01010State);
			waterInstructionsDataDto.setW01014State(w01014State);
			waterInstructionsDataDto.setW01016State(w01016State);
			waterInstructionsDataDto.setW01018State(w01018State);
			waterInstructionsDataDto.setW01019State(w01019State);
			waterInstructionsDataDto.setW21001State(w21001State);
			waterInstructionsDataDto.setW21003State(w21003State);
			waterInstructionsDataDto.setW21011State(w21011State);
			//计算综合水质等级
			WaterQualityUtil.setWaterQuality(dtoList);
			String level = waterInstructionsDataDto.getWaterQuality();
			String flag = "normal";
			//判断整条记录是不是超标数据
			if(NumberUtils.isNumber(level)) {
				String arm = WaterQualityTargetLevel.getDesc(targerWaterQuality).getStatusCode();//目标水质等级
				int armLevel = NumberUtils.createInteger(arm);
				int levelInt = NumberUtils.createInteger(level);//实际等级
				flag = levelInt > armLevel ? "unusual":"normal";
				waterInstructionsDataDto.setIsNnusual(flag);
			}
			if ("unusual".equals(flag)) {
				unualList.add(waterInstructionsDataDto);
			} else if("normal".equals(flag)){
				normalList.add(waterInstructionsDataDto);
			}
			finalList.add(waterInstructionsDataDto);
		}
		if ("unusual".equals(isNnusual)) {
			finalList = unualList;
		} else if("normal".equals(isNnusual)){
			finalList = normalList;
		}
		int count = iInstructionsService.queryRowToColHourDataCount(mn,beginTime,endTime);
		int yu = count/Integer.valueOf(pageSize);
		int mo = count%Integer.valueOf(pageSize);
		if(mo>0) {
			yu+=1;
		}
		
		Page<WaterInstructionsDataDto> page = new Page<WaterInstructionsDataDto>();
		page.setList(finalList);
		page.setPageNo(Integer.valueOf(pageNum));
		page.setPageSize(Integer.valueOf(pageSize));
		page.setTotalPages(yu);
		page.setTotalRecords(count);
		
		return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setPage(page);
	}
	
	@ApiOperation(value = "更新零点核查数据", notes = "更新零点核查数据")
	@RequestMapping(value = "/updateZeroCheckData", method = RequestMethod.POST)
	@ResponseBody
	public ResultEntity updateZeroCheckData(@RequestBody List<String> list) throws Exception {
		iInstructionsService.updateZeroCheckData(list);
		return new ResultEntity(ResultStatus.SUCCESS, Constants.UPDATE_SUCCESS);
	}
	
	@ApiOperation(value = "更新跨度核查数据", notes = "更新跨度核查数据")
	@RequestMapping(value = "/updateSpanCheckData", method = RequestMethod.POST)
	@ResponseBody
	public ResultEntity updateSpanCheckData(@RequestBody List<String> list) throws Exception {
		iInstructionsService.updateSpanCheckData(list);
		return new ResultEntity(ResultStatus.SUCCESS, Constants.UPDATE_SUCCESS);
	}
	
	@ApiOperation(value = "更新分钟实时数据", notes = "更新分钟实时数据")
	@RequestMapping(value = "/updateRealData", method = RequestMethod.POST)
	@ResponseBody
	public ResultEntity updateRealData(@RequestBody List<String> list) throws Exception {
		iInstructionsService.updateSpanCheckData(list);
		return new ResultEntity(ResultStatus.SUCCESS, Constants.UPDATE_SUCCESS);
	}
	
	@ApiOperation(value = "更新加标回收数据", notes = "更新加标回收数据")
	@RequestMapping(value = "/updateRecoveryData", method = RequestMethod.POST)
	@ResponseBody
	public ResultEntity updateRecoveryData(@RequestBody List<String> list) throws Exception {
		iInstructionsService.updateRecoveryData(list);
		return new ResultEntity(ResultStatus.SUCCESS, Constants.UPDATE_SUCCESS);
	}
	
	@ApiOperation(value = "更新标样核查数据", notes = "更新标样核查数据")
	@RequestMapping(value = "/updateCheckData", method = RequestMethod.POST)
	@ResponseBody
	public ResultEntity updateCheckData(@RequestBody List<String> list) throws Exception {
		iInstructionsService.updateCheckData(list);
		return new ResultEntity(ResultStatus.SUCCESS, Constants.UPDATE_SUCCESS);
	}
	
	@ApiOperation(value = "获取日志与状态量参数数据", notes = "获取日志与状态量参数数据")
	@RequestMapping(value = "/queryLogStatusData", method = RequestMethod.GET)
	@ResponseBody
	public ResultEntity queryLogStatusData(String mn, String beginTime, String endTime, String logType, Integer pageNumber, Integer pageSize) throws Exception {
		PageObject pageObject = new PageObject();
		pageObject.setPageNumber(pageNumber);
		pageObject.setPageSize(pageSize);
		Timestamp t1 = Water2018InstructionsHandleUtil.getTimestamp(beginTime);
		Timestamp t2 = Water2018InstructionsHandleUtil.getTimestamp(endTime);
		return iInstructionsService.queryLogStatusData(mn, t1, t2, logType, pageObject);
	}
	
	@ApiOperation(value = "获取设备因子的关键参数", notes = "获取关键参数数据")
    @RequestMapping(value = "/queryEquipmentParam", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity queryEquipmentParam(String mn, String factorCode) {
        return iInstructionsService.queryEquipmentParam(mn, factorCode);
    }
	
	@ApiOperation(value = "获取站点仪器所有监测因子参数", notes = "获取站点仪器参数 所有监测因子")
    @RequestMapping(value = "/queryEquipmentParamsInfo", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity queryEquipmentParamsInfo(String mn) {
        return iInstructionsService.queryEquipmentInfo(mn);
    }
	
	@ApiOperation(value = "获取设备具体单个因子状态信息 日志 参数或者 状态", notes = "单个因子获取设备因子信息 日志 参数或者 状态")
    @RequestMapping(value = "/queryEquipmentInfo", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity queryEquipmentInfo(String mn, String factorCode, String code) {
        return iInstructionsService.queryEquipmentInfo(mn, factorCode, code);
    }
	
	@ApiOperation(value = "获取设备五参数实时数据，分析仪状态", notes = "获取设备五参数实时数据，分析仪状态。首页弹出使用")
    @RequestMapping(value = "/queryEquipmentInfosByh", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity queryEquipmentInfosByh(String mn) {
	    ResultEntity re = null;
        try {
            re = hourDataController.queryRealTimeData(mn, "1", "10000","all");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        HashMap<String, Object> content = (HashMap<String, Object>) re.getContent();
        List<WaterInstructionsDataDto> finalList = (List<WaterInstructionsDataDto>) content.get("dataList");
        
        return iInstructionsService.queryEquipmentInfosByh(mn, finalList);
    }
	
	@ApiOperation(value = "获取设备多因子多状态信息 日志 参数或者 状态", notes = "获取设备多因子多状态信息 日志 参数或者 状态")
    @RequestMapping(value = "/queryEquipmentInfos", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity queryEquipmentInfos(String mn, String stationType) {
	    List<String> factorCodes = Arrays.asList("w01019","w21003","w21011","w21001");
	    if("002".equals(stationType)) {
	        factorCodes = Arrays.asList("w01018","w21003","w21011","w21001");
	    }
	    List<String> codes = Arrays.asList("i12003","i12001","i11001");
	    
        return iInstructionsService.queryEquipmentInfos(mn, factorCodes, codes);
    }
	
	@ApiOperation(value = "获取设备流程日志数据", notes = "获取设备流程日志数据")
    @RequestMapping(value = "/queryEquipFlowLogData", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity queryEquipFlowLogData(String mn, String beginTime, String endTime, String factorCode) throws Exception {
        Timestamp t1 = Water2018InstructionsHandleUtil.getTimestamp(beginTime);
        Timestamp t2 = Water2018InstructionsHandleUtil.getTimestamp(endTime);
        return iInstructionsService.queryEquipFlowLogData(mn, t1, t2, factorCode);
    }
	
	@ApiOperation(value = "获取监测站某因子历史小时数据", notes = "获取监测站某因子历史小时数据")
    @RequestMapping(value = "/queryHourDataByMnFactor", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity queryHourDataByMnFactor(String mn, String beginTime, String endTime, String factorCode) throws Exception {
        Timestamp t1 = Water2018InstructionsHandleUtil.getTimestamp(beginTime);
        Timestamp t2 = Water2018InstructionsHandleUtil.getTimestamp(endTime);
        return iInstructionsService.queryHourDataByMnFactor(mn, t1, t2, factorCode);
    }
	
	@ApiOperation(value = "区域水质污染趋势分析", notes = "区域水质污染趋势分析往前推一天")
    @RequestMapping(value = "/areaProjectTrendChart", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity areaProjectTrendChart() {
        return iInstructionsService.areaProjectTrendChart();
    }
	
	@ApiOperation(value = "查询多站点的联网统计率", notes = "查询多站点的联网统计率")
	@ApiImplicitParams({@ApiImplicitParam(name = "mns", value = "站点mn号1,2,3", paramType = "query", required = true, dataType = "String"),
        @ApiImplicitParam(name = "type", value = "1在线 0离线 all全部", paramType = "query", required = true, dataType = "String"),
       @ApiImplicitParam(name = "beginTime", value = "开始时间", paramType = "query", required = true, dataType = "String"),
       @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", required = true, dataType = "String")
   })
    @RequestMapping(value = "/queryMnsNetworkStatisLv", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity queryMnsNetworkStatisLv(String mns, String type, String beginTime, String endTime) {
        Timestamp t1 = Water2018InstructionsHandleUtil.getTimestamp(beginTime);
        Timestamp t2 = Water2018InstructionsHandleUtil.getTimestamp(endTime);
        return iInstructionsService.queryMnsNetworkStatisLv(mns, type, t1, t2 );
    }
	
	@ApiOperation(value = "查询站点的在线统计", notes = "查询站点的在线统计")
    @ApiImplicitParams({@ApiImplicitParam(name = "mn", value = "站点mn号", paramType = "query", required = true, dataType = "String"),
       @ApiImplicitParam(name = "beginTime", value = "开始时间", paramType = "query", required = true, dataType = "String"),
       @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", required = true, dataType = "String")
   })
    @RequestMapping(value = "/queryMnNetworkStatisLv", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity queryMnNetworkStatisLv(String mn, String beginTime, String endTime) {
        Timestamp t1 = Water2018InstructionsHandleUtil.getTimestamp(beginTime);
        Timestamp t2 = Water2018InstructionsHandleUtil.getTimestamp(endTime);
        return iInstructionsService.queryMnNetworkStatisLv(mn, t1, t2 );
    }
	
	@ApiOperation(value = "查询站点的在线统计图表", notes = "查询站点的在线统计图表")
    @ApiImplicitParams({@ApiImplicitParam(name = "mn", value = "站点mn号", paramType = "query", required = true, dataType = "String"),
       @ApiImplicitParam(name = "beginTime", value = "开始时间", paramType = "query", required = true, dataType = "String"),
       @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", required = true, dataType = "String")
   })
    @RequestMapping(value = "/queryMnNetworkEcharts", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity queryMnNetworkEcharts(String mn, String beginTime, String endTime) {
        Timestamp t1 = Water2018InstructionsHandleUtil.getTimestamp(beginTime);
        Timestamp t2 = Water2018InstructionsHandleUtil.getTimestamp(endTime);
        return iInstructionsService.queryMnNetworkEcharts(mn, t1, t2 );
    }
	
	@ApiOperation(value = "获取站点实时监控状态", notes = "获取站点实时监控状态")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "mn", value = "站点mn号", paramType = "query", required = true, dataType = "String")
   })
    @RequestMapping(value = "/queryStationRealMoin", method = RequestMethod.GET)
    @ResponseBody
    public ResultEntity queryStationRealMoin(String mn) throws IOException {
        return iInstructionsService.queryStationRealMoin(mn );
    }

}
